import React from 'react'
import {Col, Row,Icon} from "antd";

import {WeaLocaleProvider,WeaInput,WeaColorPicker,WeaHelpfulTip,WeaSelect,WeaBrowser} from "ecCom";
const getLabel = WeaLocaleProvider.getLabel;
import {WeaPortalShare,WeaMaterialLib} from 'weaPortalPublic';
import weaPortal from 'weaPortal'

export default class AddExtends extends React.Component{

    componentWillMount(){
        const {setSetting,setId} = this.props
        if(setId == -1){
            setSetting({
                img:'/wui/theme/ecology9/image/layout/layout5/desktop-icon-default.png',
                urlType:'0',
                bgc:'#ffffff'
            })
        }
    }

    render(){
        const {setting,setSetting} = this.props
        const {img,urlType='0',url='',urlReplaceDatas,bgc="#ffffff"} = setting

        return (
            <div>
                <div className="set-item">
                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@43pg6q`} type="flex" middle="middle">
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@4r7mgh`} span={6} >
                            <div className="item-title">{getLabel(520033, '图标')} :</div>
                            <div className="middle-box"></div>
                        </Col>
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@bbid7q`} span={18}>
                            <WeaMaterialLib ecId={`${this && this.props && this.props.ecId || ''}_WeaMaterialLib@fcex42`}
                                multiCheck={false}
                                value={img}
                                isShow={true}
                                onChange={value => setSetting({img: value})}
                            />
                        </Col>
                    </Row>
                </div>
                <div className="set-item">
                    <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@jslcbv`} type="flex" middle="middle">
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@hxyojs`} span={6} >
                            <div className="item-title">{getLabel(16208,'链接地址')} :</div>
                            <div className="middle-box"></div>
                        </Col>
                        <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@9dve0i`} span={18}>
                            <Row ecId={`${this && this.props && this.props.ecId || ''}_Row@1np7pz`} gutter={8}>
                                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@y8osfx`} span={7}>
                                    <WeaSelect ecId={`${this && this.props && this.props.ecId || ''}_WeaSelect@pho4qu`}
                                        options={[
                                            {key: '0', selected: false, showname: getLabel(385809, '自定义URL')},
                                            {key: '1', selected: false, showname: getLabel(33496, '系统菜单')},
                                            {key: '2', selected: false, showname: getLabel(31560, '系统页面')},
                                        ]}
                                        value={urlType}
                                        onChange={value => setSetting({urlType: value,urlReplaceDatas:[],url:''})}
                                    />
                                </Col>
                                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@193lhd`} span={16}>
                                    {
                                        urlType == '0' ?
                                            <WeaInput ecId={`${this && this.props && this.props.ecId || ''}_WeaInput@s8t00i`} value={url} onChange={value => setSetting({url: value})}/>
                                            : null
                                    }
                                    {
                                        urlType == '1' ? (
                                            <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@pph544`}
                                                title={getLabel(33496, '系统菜单')}
                                                type={'portalmenu'}
                                                tabs={[
                                                    {name: getLabel(33675, '前端菜单'), key: '1', dataParams: {sourcetype: '1'}, conditionDataParams: {sourcetype: '1'}},
                                                    {name: getLabel(33676, '后端菜单'), key: '2', dataParams: {sourcetype: '2'}, conditionDataParams: {sourcetype: '2'}},
                                                    {name: getLabel(18773, '自定义菜单'), key: '3', dataParams: {sourcetype: '3'}, conditionDataParams: {sourcetype: '3'}},
                                                    {name: getLabel(23094, '系统门户页面'), key: '4', dataParams: {sourcetype: '4'}, conditionDataParams: {sourcetype: '4'}}
                                                ]}
                                                replaceDatas={urlReplaceDatas}
                                                onChange={(id, name, data) => {setSetting({urlReplaceDatas:data,url:(data.length > 0 ? data[0].fullrouteurl ||data[0].linkAddress ||"":"")})}}
                                            />
                                        ) : null
                                    }
                                    {
                                        urlType == '2' ? (
                                            <WeaBrowser ecId={`${this && this.props && this.props.ecId || ''}_WeaBrowser@q8krh5`}
                                                _uuid={'ff56d18b7d98461d808a1f2937a3ba1d'}
                                                title={getLabel(31560, '系统页面')}
                                                isSingle={false}
                                                type={'systempage'}
                                                tabs={[
                                                    {name: getLabel(22243, '文档'), key: '1', dataParams: {sourcetype: '1'}},
                                                    {name: getLabel(30045, '流程'), key: '2', dataParams: {sourcetype: '2'}},
                                                ]}
                                                replaceDatas={urlReplaceDatas}
                                                onChange={(id, name, data) =>{
                                                    let menuhref = '';
                                                    if(data[0].activeKey == '1'){
                                                        menuhref = data[0].dropMenuUrl + id;
                                                        setSetting({urlReplaceDatas:data,url: menuhref})
                                                    }else if(data[0].activeKey == '2'){
                                                        let arr = id.split(',');
                                                        let wftypeIds = [];
                                                        let wfIds = [];
                                                        arr.map((item) => {
                                                            if(item.lastIndexOf('wftype') != -1){
                                                                wftypeIds.push(item.split('wftype_').join(''));
                                                            }else{
                                                                wfIds.push(item.split('wf_').join(''));
                                                            }
                                                        });
                                                        data.map(item => {
                                                            if(item.allVersionIds && item.allVersionIds != '') {
                                                                const allVersionIdsArrs = item.allVersionIds.split(',');
                                                                if(allVersionIdsArrs.length > 1) {
                                                                    allVersionIdsArrs.map(allVersionIdsItem => {
                                                                        if(allVersionIdsItem != '') {
                                                                            wfIds.push(allVersionIdsItem);
                                                                        }
                                                                    })
                                                                }else {
                                                                    wfIds.push(allVersionIdsArrs.join(''));
                                                                }
                                                            }
                                                        })
                                                        let viewType = '';
                                                        if(data[0].dropMenuValue == '1'){
                                                            let jsonstr = 'wfRange=' + wfIds.toString();
                                                            menuhref = data[0].dropMenuUrl + jsonstr;
                                                            setSetting({urlReplaceDatas:data,url: menuhref})
                                                            return;
                                                        }else if(data[0].dropMenuValue == '2'){
                                                            viewType = "1";
                                                        }else if(data[0].dropMenuValue == '3'){
                                                            viewType = "2";
                                                        }else if(data[0].dropMenuValue == '4'){
                                                            viewType = "3";
                                                        }else if(data[0].dropMenuValue == '5'){
                                                            viewType = "5";
                                                        }else if(data[0].dropMenuValue == '6'){
                                                            viewType = "6";
                                                        }else if(data[0].dropMenuValue == '7'){
                                                            viewType = "4";
                                                        }
                                                        let jsonstr = {
                                                            flowids:wfIds,
                                                            viewType:viewType,
                                                            typeids:wftypeIds,
                                                            isExclude : 0
                                                        };
                                                        if(viewType== '2'){
                                                            jsonstr.isArrangement =1;
                                                        }else if(viewType == '1'){
                                                            jsonstr.showView =1;
                                                        }
                                                        menuhref = data[0].dropMenuUrl + escape(JSON.stringify(jsonstr.toString()));
                                                        setSetting({urlReplaceDatas:data,url: menuhref})
                                                    }
                                                }}
                                            />
                                        ) : null
                                    }
                                </Col>
                                <Col ecId={`${this && this.props && this.props.ecId || ''}_Col@nmdca6`} span={1}>
                                    <div style={{position: 'absolute', top: '6px'}}>
                                        <WeaHelpfulTip ecId={`${this && this.props && this.props.ecId || ''}_WeaHelpfulTip@p1f66r`} title={getLabel('386567', '外部地址，请在地址前加上http://或https://')}/>
                                    </div>
                                </Col>
                            </Row>
                        </Col>
                    </Row>
                </div>

            </div>
        )
    }
}